/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.constant.enums;

import cn.hutool.core.util.ArrayUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

/**
 * 告警枚举
 *
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.1.0
 * @since 2024/7/11 17:19
 */
@Getter
@AllArgsConstructor
public enum MachineAlarmEnum {

    MACHINE_ALARM_OFFLINE(0, "offlineAlarmSwitch", "无信号警告"),
    MACHINE_ALARM_POWER(1, "powerAlarmSwitch", "断电警告"),
    MACHINE_ALARM_GEO(2, "geoAlarmSwitch", "超区警告"),
    MACHINE_ALARM_IDLE(3, "idleAlarmSwitch", "闲置警告"),
    MACHINE_ALARM_LOCATION(4, "locationAlarmSwitch", "无定位警告"),
    MACHINE_ALARM_ILLEGALITY_MOVE(5, "illegalityMoveSwitch", "非法移动警告"),
    MACHINE_ALARM_LOSE(6, "machineLoseSwitch", "丢失车辆警告"),
    MACHINE_ALARM_BATTER_LOCK(7, "batterLockSwitch", "未关电池锁车辆警告"),
    MACHINE_ALARM_ROLLOVER(8, "rolloverSwitch", "侧翻车辆警告"),
    MACHINE_ALARM_CAMERA(9, "cameraSwitch", "摄像头通讯故障"),
    MACHINE_ALARM_CAMERA_COVER(10, "cameraCoverSwitch", "摄像头遮挡"),
    MACHINE_ALARM_OUTBOUNDS(11, "geoOutBoundsSwitch", "出界超速"),


    ;

    private final Integer alarmType;
    private final String alarmCode;
    private final String alarmDesc;

    public static Integer getTypeByCode(String alarmTypeCode) {
        return Optional.ofNullable(ArrayUtil.firstMatch(machineAlarm -> machineAlarm.getAlarmCode().equals(alarmTypeCode), MachineAlarmEnum.values()))
                .map(MachineAlarmEnum::getAlarmType).orElse(-1);
    }
}
